﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;

namespace EmployeeCheckIn
{
    public partial class _Default : System.Web.UI.Page
    {   
        string UserDB,PassDB;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session.Clear();            
                if (Session["User"]!=null)
                {
                    lbResponse.Text = Session["User"].ToString();
                    lbWarning.Text = "คุณยังไมได้ออดจากระบบ";
                    lbWarning.ForeColor = System.Drawing.ColorTranslator.FromHtml("black");
                    //Response.Write("<script>alert('คุณยังไม่ได้ออกจากระบบ!'); window.location='MenuAdmin.aspx';</script>");
                }
            }
          

            
        }

       protected void btLogIn_Click1(object sender, EventArgs e)
        {
            Log_in in_log = new Log_in();
            string Username = txtUserName.Text.ToLower();
            string Password = EncyptMd5.getMd5Hash(txtPassWord.Text);
            string Admin_id;
            string status;
            DataTable dt = in_log.GetData(Username, Password);

            if (dt != null && dt.Rows.Count > 0)
            {
                UserDB = dt.Rows[0]["user_name"].ToString();
                PassDB = dt.Rows[0]["user_password"].ToString();
                Admin_id = dt.Rows[0]["admin_id"].ToString();
                status = dt.Rows[0]["admin_status_id"].ToString();
                Session["User"] = Username;
                Session["pass"] = Password;
                Session["admin_id"] = Admin_id;
                Session["status"] = status;
                Server.Transfer("MenuAdmin.aspx");
                lbWarning.Text = "Enter Username and Password";
                //login sucuccess            
            }
            else
            {

                lbWarning.Text = "That username or password is incorrect";
                lbWarning.ForeColor = System.Drawing.ColorTranslator.FromHtml("red");
                
                //nuek commit
                //Sunny commit
                //somnuek agian
                //pure comit
                //sunny again
                //pong commit
                //pong commit r click

            }

        }

       protected void btcancel_Click(object sender, EventArgs e)
       {
           txtPassWord.Text = "";
           txtUserName.Text = "";
       }

       

       
        
	
		 
	}
    }

